package views;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionListener;

/**
 * Created with IntelliJ IDEA.
 * User: Артемка
 * Date: 30.11.13
 * Time: 17:54
 * To change this template use File | Settings | File Templates.
 */
public class StudentView extends JFrame {
    private JButton addButton, cancelButton;
    private JTextField tf1, tf2, tf3, tf4, tf5, tf6;
    private JTextArea ta1, ta2, ta3, ta4, ta5, ta6;
    private JPanel panel;
    private GridBagLayout layout;
    private JComboBox groupBox;

    public StudentView() {


        layout = new GridBagLayout();
        panel = new JPanel(layout);

        addButton = new JButton("Добавить");
        cancelButton = new JButton("Отмена");

        tf1 = new JTextField("", 20);
        tf2 = new JTextField("", 20);
        tf3 = new JTextField("", 20);
        groupBox = new JComboBox() ;
        tf6 = new JTextField("", 10);

        ta1 = new JTextArea("Фамимлия:");
        ta2 = new JTextArea("Имя:");
        ta3 = new JTextArea("Отчество:");
        ta4 = new JTextArea("Группа:");

        ta6 = new JTextArea("Дата зачисления:");

       panel.add(ta1, new GridBagConstraints(0, 0, 1, 1, 0, 0, GridBagConstraints.WEST,
                GridBagConstraints.NONE, new Insets(0, 0, 5, 5), 0, 0));
        panel.add(tf1, new GridBagConstraints(0, 1, 1, 1, 0, 0, GridBagConstraints.EAST,
                GridBagConstraints.NONE, new Insets(0, 0, 5, 5), 0, 0));
        panel.add(ta2, new GridBagConstraints(0, 2, 1, 1, 0, 0, GridBagConstraints.WEST,
                GridBagConstraints.NONE, new Insets(0, 0, 5, 5), 0, 0));
        panel.add(tf2, new GridBagConstraints(0, 3, 1, 1, 0, 0, GridBagConstraints.EAST,
                GridBagConstraints.NONE, new Insets(0, 0, 5, 5), 0, 0));
        panel.add(ta3, new GridBagConstraints(0, 4, 1, 1, 0, 0, GridBagConstraints.WEST,
                GridBagConstraints.NONE, new Insets(0, 0, 5, 5), 0, 0));
        panel.add(tf3, new GridBagConstraints(0, 5, 1, 1, 0, 0, GridBagConstraints.EAST,
                GridBagConstraints.NONE, new Insets(0, 0, 5, 5), 0, 0));
        panel.add(ta4, new GridBagConstraints(1, 0, 1, 1, 0, 0, GridBagConstraints.WEST,
                GridBagConstraints.NONE, new Insets(0, 0, 5, 5), 0, 0));
        panel.add(groupBox, new GridBagConstraints(1, 1, 1, 1, 0, 0, GridBagConstraints.EAST,
                GridBagConstraints.NONE, new Insets(0, 0, 5, 5), 0, 0));


        panel.add(ta6, new GridBagConstraints(1, 4, 1, 1, 0, 0, GridBagConstraints.WEST,
                GridBagConstraints.NONE, new Insets(0, 0, 5, 5), 0, 0));
        panel.add(tf6, new GridBagConstraints(1, 5, 1, 1, 0, 0, GridBagConstraints.EAST,
                GridBagConstraints.NONE, new Insets(0, 0, 5, 5), 0, 0));
        panel.add(addButton, new GridBagConstraints(0, 6, 1, 1, 0, 0, GridBagConstraints.WEST,
                GridBagConstraints.NONE, new Insets(20, 20, 5, 5), 0, 0));
        panel.add(cancelButton, new GridBagConstraints(0, 6, 1, 1, 0, 0, GridBagConstraints.EAST,
                GridBagConstraints.NONE, new Insets(20, 0, 5, 5), 20, 0));

        add(panel);
    }

    public void addListenerForAdd(ActionListener listener) {
        addButton.addActionListener(listener);
    }

    public void addListenerForCancel(ActionListener listener) {
        cancelButton.addActionListener(listener);
    }



    public String getName(){
        return tf1.getText();
    }
    public void setName(String name){
        this.tf1.setText(name);
    }
    public String getSurname(){
        return tf2.getText();
    }
    public void setSurname(String surname){
        this.tf2.setText(surname);
    }
    public String getPatronymic(){
        return tf3.getText();
    }
    public void setPatronymic(String patr){
       this.tf3.setText(patr);
    }
    public int getGroup(){
        return groupBox.getSelectedIndex();
    }
    //public void setGroup(int index, ){}

    public String getDate(){
        return tf6.getText();
    }
    public  void setDate(String date){
        this.tf6.setText(date);
    }

    public void errorMessage(String s){
        JOptionPane.showMessageDialog(this, s, "Ошибка!", JOptionPane.WARNING_MESSAGE);
    }

    public void addMessage(String s){
        JOptionPane.showMessageDialog(this, s,"Поздравляем!", JOptionPane.INFORMATION_MESSAGE);
    }

}
